/** 
    @file text_overlay.hpp
    @brief Text output onto the HUD
*/

#ifndef PM3_HUD_TEXT_H
#define PM3_HUD_TEXT_H

#include <Ogre.h>
#include <OgreSingleton.h>

namespace pm3 {

    //! GUI-related stuff
    namespace hud {
        /**
            @class TEXT_OVERLAY
            @brief A text overlay singleton
        */
        class TEXT_OVERLAY: public Ogre::Singleton<TEXT_OVERLAY> {
        public:
            /**
                @brief A constructor
            */
            TEXT_OVERLAY();
            /**
                @brief A destructor
            */
            ~TEXT_OVERLAY();

            /**
                @brief Adds a textbox onto the overlay
                @param[in] r_name Reference to an identifier string for the textbox
                @param[in] r_text Reference to the text
                @param[in] f_x Textbox position X-coordinate
                @param[in] f_y Textbox position Y-coordinate
                @param[in] f_width Textbox width
                @param[in] f_height Textbox height
                @param[in] r_color Textbox color
            */
            void add_textbox( const std::string &r_name, const std::string &r_text, 
                              Ogre::Real f_x, Ogre::Real f_y, Ogre::Real f_width, Ogre::Real f_height,
                              const Ogre::ColourValue &r_color = Ogre::ColourValue( 1.0, 1.0, 1.0, 1.0 ) );

            /**
                @brief Removes a textbox from the overlay
                @param[in] r_name Reference to the identifier of the textbox to be removed
            */
            void remove_textbox( const std::string &r_name );

            /**
                @brief Sets the text in a textbox
                @param[in] r_name Reference to the identifier of the textbox
                @param[in] r_text Reference to the text to be set
            */
            void set_text( const std::string &r_name, const std::string &r_text );

            /**
                @brief Printf-style output onto the text overlay
                @param[in] r_name Reference to the identifier of the textbox
                @param[in] p_fmt Pointer to the format string
            */
            void printf( const std::string &r_name, const char *p_fmt, ... );

            /**
                @brief Shows the text overlay
            */
            void show();

            /**
                @brief Hides the text overlay
            */
            void hide();

            /**
                @brief Checks if the overlay is visible
                @return True if it is and false if it is not
            */
            inline bool is_visible() { return m_visible; }

            /**
                @brief Checks the internal pointers
                @return True if everything is valid for use, false otherwise
            */
            bool is_valid();

        private:
            /**
                @brief Creates the text overlay
            */
            void create();
            /**
                @brief Destroys it
            */
            void destroy();

            //! Pointer to the Ogre overlay manager singleton
            Ogre::OverlayManager *m_overlay_manager;
            //! Pointer to Ogre overlay
            Ogre::Overlay *m_overlay;
            //! Pointer to Ogre overlay container
            Ogre::OverlayContainer *m_panel;
            //! Is this overlay visible?
            bool m_visible;

            //! Initial buffer size for printf-like text output
            static const int m_format_buffer_size = 256;
        };
    }
}

#endif
